package cn.sczhyt.modules.szhy.controller;

import java.util.Arrays;
import java.util.Map;

import cn.sczhyt.modules.szhy.entity.MeetingEntity;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.sczhyt.modules.szhy.entity.MeetingTopicsEntity;
import cn.sczhyt.modules.szhy.service.MeetingTopicsService;
import cn.sczhyt.common.utils.PageUtils;
import cn.sczhyt.common.utils.R;



/**
 * 会议议题表
 *
 * @author luoshijie
 * @email 1169414426@qq.com
 * @date 2020-11-10 09:31:42
 */
@Api(tags = "PC端议题管理")
@RestController
@RequestMapping("szhy/meetingtopics")
public class MeetingTopicsController {
    @Autowired
    private MeetingTopicsService meetingTopicsService;
    /**
     * 列表
     */
    @ApiOperation("列表")
    @PostMapping("/list")
   // @RequiresPermissions("szhy:meetingtopics:list")
    public R list(@RequestParam(defaultValue = "1") Integer page,
                  @RequestParam(defaultValue = "20") Integer limit,
                  @RequestParam String id,
                  @RequestBody(required = false) MeetingTopicsEntity meetingTopicsEntity){

        IPage<MeetingTopicsEntity> iPage = meetingTopicsService.findList(page, limit,id,meetingTopicsEntity);
        PageUtils pages = new PageUtils(iPage);
        return R.ok().put("data", pages);
    }


    /**
     * 信息
     */
    @ApiOperation("信息")
    @GetMapping("/info/{topicsId}")
   // @RequiresPermissions("szhy:meetingtopics:info")
    public R info(@PathVariable("topicsId") String topicsId){
		MeetingTopicsEntity meetingTopics = meetingTopicsService.getById(topicsId);

        return R.ok().put("meetingTopics", meetingTopics);
    }

    /**
     * 保存或修改
     */
    @ApiOperation("保存")
    @PostMapping("/save")
    public R save(@RequestBody MeetingTopicsEntity meetingTopics){
        if(meetingTopics.getTopicsId().isEmpty()){
            meetingTopicsService.save(meetingTopics);
        }else{
            meetingTopicsService.updateById(meetingTopics);
        }
        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation("修改")
    @PostMapping("/update")
   // @RequiresPermissions("szhy:meetingtopics:update")
    public R update(@RequestBody MeetingTopicsEntity meetingTopics){
		meetingTopicsService.updateById(meetingTopics);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation("删除")
    @PostMapping("/delete")
   // @RequiresPermissions("szhy:meetingtopics:delete")
    public R delete(@RequestBody String[] topicsIds){
		meetingTopicsService.removeByIds(Arrays.asList(topicsIds));

        return R.ok();
    }

}
